package Part;

import java.awt.Graphics2D;

import com.golden.gamedev.object.SpriteGroup;

public class Parts extends SpriteGroup 
{
	private final static double PI_2 = 2 * Math.PI;
	
	public Parts()
	{
		super("Parts");
	}
	
	public void spawnBurst (double x, double y)
	{
		// generate a list of parts
		y += 5;
		for (int i = 0; i < 26; i++)
        {
            double angle = randDouble(0, PI_2);
            double magnitude = randDouble(50, 100);
            Part part = new Part(x, y, 
            		            magnitude * Math.cos(angle), magnitude * Math.sin(angle) - magnitude, 
            		            randDouble(3, 4.2));
            part.setLife(part.getLife()+randDouble(0, 0.2));
            part.setLocation(part.getX() + part.getVX()/80, part.getY() + part.getVY()/80);
            part.setActive(true);
            add(part);
        }
	}
	
	public void spawnBiggerBurst (double x, double y)
    {
        for (int i = 0; i < 30; i++)
        {
            double angle = randDouble(0, PI_2);
            double magnitude = randDouble(140, 310);
            Part part = new Part(x, y, 
            		            magnitude * Math.cos(angle), magnitude * Math.sin(angle), 
            		            randDouble(3, 3.8));
            part.setLife(part.getLife()+randDouble(0, 0.4));
            part.setLocation(part.getX() + part.getVX()/80, part.getY() + part.getVY()/80);
            part.setActive(true);
            add(part);
        }
    }
	
	public double randDouble (double min, double max)
    {
        return min + Math.random() * (max - min);
    }
	
	@Override
    public void update(long elapsedTime)
    {
		// TODO: need some mechanism to set sprite inactive
		removeInactiveSprites();
		super.update(elapsedTime);
    }
	
	/*
	@Override
    public void render(Graphics2D g)
    {
    	super.render(g);
    }
    */
}
